<?php


namespace app\common\wechat;

/**
 * 获取微信登陆
 * Class WeChat
 * @package app\api\common
 */
class WechatConfig
{
    protected $sysConfig;

    public function __construct()
    {
        $weChatConf = get_system_config('wechat');
        $this->appid = $weChatConf['xcx_appid']; //小程序appid
        $this->app_secret = $weChatConf['xcx_appsecret'];//小程序appsecret
        $this->mchid = $weChatConf['mchid']; // 产品中心-开发配置-商户号
        $this->apiKey = $weChatConf['secrect_key'];//帐户设置-安全设置-API安全-API密钥-设置API密钥*/支付API密钥
        $this->notify_url=$weChatConf['pay_back_url'];
        $this->wx_appid = $weChatConf['appid']; //公众号appid
        $this->wx_apk=$weChatConf['appsecret'];//公众号appsecret
    }

    public function httpRequest($url,$data='',$method='GET'){
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL,$url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($curl, CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
        if($method=='POST')
        {
            curl_setopt($curl, CURLOPT_POST, 1);
            if ($data !='')
            {
                curl_setopt($curl, CURLOPT_POSTFIELDS,$data);
            }
        }

        curl_setopt($curl, CURLOPT_TIMEOUT, 30);
        curl_setopt($curl, CURLOPT_HEADER, 0);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $result = curl_exec($curl);
        curl_close($curl);
        return $result;
    }
}